package com.stylefeng.guns.modular.skate.service.impl;

import java.util.List;
import java.util.Map;

import com.stylefeng.guns.common.persistence.model.Skate;
import com.stylefeng.guns.common.persistence.dao.SkateMapper;
import com.stylefeng.guns.modular.skate.service.ISkateService;
import com.stylefeng.guns.modular.system.dao.SkateDao;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2020-12-20
 */
@Service
public class SkateServiceImpl extends ServiceImpl<SkateMapper, Skate> implements ISkateService {
	@Autowired
	private SkateDao skateDao;
	
	public Page<Map<String, Object>>  selectByCondition(Page<Map<String, Object>> page,String name,Integer type,String color,Integer level) {
		List<Map<String, Object>> selectList = skateDao.selectByCondition(page, name, type,color,level);
		List<Map<String, Object>> result = Lists.newArrayList();
		for (Map<String,Object> skate : selectList) {
			Map<String, Object> temp = Maps.newHashMap();
			temp.put("id", skate.get("id"));
			temp.put("name", skate.get("name"));
			if (skate.get("type") != null) {
				if (Integer.valueOf(skate.get("type").toString()) == 1) {
					temp.put("type", "28~31码");
				}
				if (Integer.valueOf(skate.get("type").toString()) == 2) {
					temp.put("type", "32~35码");
				}
				if (Integer.valueOf(skate.get("type").toString()) == 3) {
					temp.put("type", "36~39码");
				}
			} else {
				temp.put("type", "");
			}
			temp.put("number", skate.get("number"));
			if (skate.get("level") != null) {
				if (Integer.valueOf(skate.get("level").toString()) == 1) {
					temp.put("level", "儿童鞋");
				}
				if (Integer.valueOf(skate.get("level").toString()) == 2) {
					temp.put("level", "成人鞋");
				}
			} else {
				temp.put("level", "");
			}
			temp.put("price", skate.get("price"));
			temp.put("sum", skate.get("sum"));
			temp.put("color", skate.get("color"));
			temp.put("createTime", skate.get("createTime"));
			result.add(temp);
		}
		page.setRecords(result);
		return page;
	}
}
